<template>
  <div class="login">
    <Login @on-submit="handleSubmit">
      <UserName name="username" />
      <Password name="password" />
      <div class="demo-auto-login ivu-mt-8">
        <a @click="handleClick">忘记密码 {{ access }}</a>
      </div>
      <Submit />
    </Login>
  </div>
</template>
<script>
import { post } from "@/utils/http";
export default {
  name: "LoginView",
  data() {
    return {};
  },
  methods: {
    handleSubmit(valid, { username, password }) {
      let ctx = this;
      if (valid) {
        post("login.php", { username, password }).then((res) => {
          if (res.code === 200) {
            ctx.$router.push("/");
            ctx.$Notice.success({
              title: "登陆成功!",
            });
            ctx.$store.commit("increment", res.sys);
          } else {
            ctx.$Notice.error({
              title: res.status,
            });
          }
        });
      }
    },
  },
};
</script>
<style>
.login {
  height: 100vh;
  justify-content: center;
  display: flex;
  align-items: center;
}

.login .ivu-login {
  width: 400px;
}

.demo-auto-login {
  margin-bottom: 24px;
  text-align: left;
}

.demo-auto-login a {
  float: right;
}
</style>
